#include <kvs/Timer>
#include <kvs/UnstructuredVolumeImporter>
#include <cl/CellLocatorBIH.h>


int main( int argc, char** argv )
{
    std::string filename = argv[1];
    kvs::UnstructuredVolumeObject* volume = new kvs::UnstructuredVolumeImporter( filename );

    //single threaded mode
    std::cout << "Single threaded mode\n";
    kvstensorvis::cl::CellLocatorBIH* locator_s = new kvstensorvis::cl::CellLocatorBIH( volume );
    locator_s->build();

    //double threaded mode
    std::cout << "\nDouble threaded mode\n";
    kvstensorvis::cl::CellLocatorBIH* locator_d = new kvstensorvis::cl::CellLocatorBIH( volume );
    locator_d->setParallel();
    locator_d->build();

    std::cout << "\nWriting Test\n";
    locator_d->write("ctd.dat");

    std::cout << "\nReading Test\n";
    kvstensorvis::cl::CellLocatorBIH* locator = new kvstensorvis::cl::CellLocatorBIH( volume );
    locator->read("ctd.dat");

    std::cout << "\nComparing Test\n";
    std::cout << "Comparing double thread cell tree and written-then-readback cell tree: " << locator->check(locator_d) << std::endl;
    std::cout << "Comparing double thread cell tree and single thread cell tree:         " << locator_d->check(locator_s) << std::endl;

    delete locator_s;
    delete locator_d;

    return 0;
}
